import operate from '@dfeidao/atom-nodejs/db/operate';
import uuid from 'uuid';

import doc_code from '@dfeidao/atom-nodejs/msg/doc-code';

interface Message {
	role_name: string;
	role_type_id: string;
	create_time: string;
	icon: string;
	productid: string;
}

export default async function atom(msg: Message, action_id: string, session_id: string, spaceid: string) {
	const systemid = '12';
	// const { exec, prepare } = insert(action_id, session_id, spaceid, systemid);
	const { exec, insert } = operate(action_id, session_id, systemid);
	const role_no = await doc_code(action_id, session_id, spaceid, systemid, 'BM0011274', 1);
	insert('pub_role', { _id: uuid(), role_name: msg.role_name, role_type_id: msg.role_type_id, create_time: msg.create_time, icon: msg.icon, productid: msg.productid, role_no: role_no.result });
	const res = await exec();
	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}
